import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import weka.classifiers.Classifier;
import weka.classifiers.CostMatrix;
import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayes;
import weka.classifiers.meta.CostSensitiveClassifier;
import weka.classifiers.rules.OneR;
import weka.classifiers.trees.J48;
import weka.core.Instance;
import weka.core.Instances;
import classifier.CancerModel;
import dataEntity.ClassifierData;
import dataEntity.Demographics;
import dataEntity.LeadingCausesOfDeath;
import dataEntity.MeasuresOfBirthAndDeath;
import dataEntity.PreventiveServicesUse;
import dataEntity.RelativeHealthImportance;
import dataEntity.RiskFactorsAndAccessToCare;
import dataEntity.SummaryMeasuresOfHealth;
import dataEntity.VunerablePopsAndEnvHealth;
import dataEntity.Weather;
import dataMapper.DemographicsMapper;
import dataMapper.LeadingCausesOfDeathMapper;
import dataMapper.MapIndexMapper;
import dataMapper.MeasuresOfBirthAndDeathMapper;
import dataMapper.PreventiveServicesUseMapper;
import dataMapper.RelativeHealthImportanceMapper;
import dataMapper.RiskFactorsAndAccessToCareMapper;
import dataMapper.SummaryMeasuresOfHealthMapper;
import dataMapper.VunerablePopsAndEnvHealthMapper;
import dataMapper.WeatherFileMapper;

public class DataProcessing{
	private static final String TEST_FILE_LOCATION = "./dataFiles/test.arff";
	private Map<String,Map<String,Demographics>> demographicsMap;
	private Map<String,Map<String,LeadingCausesOfDeath>> deathMap;
	private Map<String,Map<String,MeasuresOfBirthAndDeath>> measuresMap;
	private Map<String,Map<String,PreventiveServicesUse>> preventiveMap;
	private Map<String,Map<String,RelativeHealthImportance>> relativeMap;
	private Map<String,Map<String,RiskFactorsAndAccessToCare>> riskMap;
	private Map<String,Map<String,SummaryMeasuresOfHealth>> summaryMap;
	private Map<String,Map<String,VunerablePopsAndEnvHealth>> vunerableMap;
	private Map<String,Map<String,Weather>> weatherMap;
	private Map<String,Map<String,Integer>> mapIndex;
	String[] processingStates = {"CA","WA","OR","CO"};
	public DataProcessing(){
		readFiles();
//		writeFile();
//		processData();
//		processData2();
//		processData3();
//		processData4();
//		processDataCostMatrix();
//		processDataCostMatrix2();
//		processDataCostMatrix3();
//		checkKeys(demographicsMap,mapIndex);
//		System.out.println("Complete");
//		checkKeys(mapIndex,demographicsMap);
//		System.out.println("Complete");
//		createClassMapData();
//		processTest();
//		createModelObject();
	}
	private void processTest() {
		BufferedReader reader;
		try{
			Map<Integer,String> dataIndex = new HashMap<Integer,String>();
			reader = new BufferedReader(new FileReader(TEST_FILE_LOCATION));
			Instances data = new Instances(reader);
			reader.close();
			// setting class attribute
			for(int k = 0; k < data.numInstances(); k++){
				Instance s = data.instance(k);
				String county = s.toString(1);
				if(county.contains(" "))
					county = county.substring(1, county.length()-1);
				if(county.contains("\\'"))
					county = county.replace("\\'", "'");
				if(s.toString(0).equals("IA") && county.equals("'O'Brien'"))
					county = "O'Brien";
				dataIndex.put(k, s.toString(0)+","+county);
			}
			data.setClassIndex(data.numAttributes() - 1);
			data.deleteAttributeAt(0);
			data.deleteAttributeAt(0);

			String[] indexedString = new String[3135];

			ObjectInputStream ois = new ObjectInputStream(new FileInputStream("./objects/OneRRatioCostMatrixModel"));
			ClassifierData cd = (ClassifierData) ois.readObject();
			ois.close();

			for(int k = 0; k < data.numInstances(); k++){
				int classifier = (int) cd.getClassifier().classifyInstance(data.instance(k));
				String[] indexString = dataIndex.get(k).split(",");
				Integer index = mapIndex.get(indexString[0]).get(indexString[1]);
				if(index != null)
					indexedString[index-1] = (classifier == 0 ? "1" : "0") + "\t" + (classifier == 1 ? "1" : "0") + "\t" + (classifier == 2 ? "1" : "0") + "\t" + (classifier == -1 ? "1" : "0")
						+ "\t\t" + (data.instance(k).classIsMissing() ? "0\t0\t0\t1" : classifier == (int)data.instance(k).classValue() ? "1\t0\t0\t0" : "0\t0\t1\t0")
						;
			}
			for(String s : indexedString){
				System.out.println(s);
			}
//			System.out.println(cd.getSummary());
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void createModelObject(){
		try {
			long start;
			long total;
			BufferedReader reader = new BufferedReader(new FileReader(TEST_FILE_LOCATION));
			Instances data = new Instances(reader);
			reader.close();
			data.setClassIndex(data.numAttributes() - 1);
			data.deleteAttributeAt(0);
			data.deleteAttributeAt(0);
			// classifier
			Classifier cfr = getJ48();
	
			Evaluation eval = new Evaluation(data);
			eval.crossValidateModel(cfr, data, 10, new Random(1));
			start = System.currentTimeMillis();
			cfr.buildClassifier(data);
			total = System.currentTimeMillis() - start;

//			ClassifierData cd = new ClassifierData();
//			cd.setClassifier(cfr);
//			cd.setName("J48");
//			cd.setSummary(getSummary(eval, cfr, total, true));
//			ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("./objects/J48Model"));
//			oos.writeObject(cd);
//			oos.flush();
//			oos.close();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private Classifier getOneR(){
		OneR nb = new OneR();
		return nb;
	}
	private Classifier getOneRCostMatrix(){
		OneR nb = new OneR();

		CostMatrix cm = new CostMatrix(3);
		cm.setElement(0, 0, 0.0);
		cm.setElement(1, 0, 3.32);
		cm.setElement(2, 0, 8.44);

		cm.setElement(0, 1, 1.0);
		cm.setElement(1, 1, 0.0);
		cm.setElement(2, 1, 8.44);

		cm.setElement(0, 2, 1.0);
		cm.setElement(1, 2, 3.32);
		cm.setElement(2, 2, 0.0);
		
		CostSensitiveClassifier ccc = new CostSensitiveClassifier();
		ccc.setClassifier(nb);
		ccc.setCostMatrix(cm);
		ccc.setMinimizeExpectedCost(false);
		ccc.setSeed(1);
		return ccc;
	}
	private Classifier getJ48CostMatrix(){
		J48 nb = new J48();
		nb.setConfidenceFactor(0.33f);
		nb.setBinarySplits(true);
		nb.setMinNumObj(9);
		nb.setNumFolds(3);
		nb.setReducedErrorPruning(true);
		nb.setSaveInstanceData(false);
		nb.setSeed(1);
		nb.setSubtreeRaising(false);
		nb.setUnpruned(false);
		nb.setUseLaplace(true);

		CostMatrix cm = new CostMatrix(3);
		cm.setElement(0, 0, 0.0);
		cm.setElement(1, 0, 3.32);
		cm.setElement(2, 0, 8.44);

		cm.setElement(0, 1, 1.0);
		cm.setElement(1, 1, 0.0);
		cm.setElement(2, 1, 8.44);

		cm.setElement(0, 2, 1.0);
		cm.setElement(1, 2, 3.32);
		cm.setElement(2, 2, 0.0);
		
		CostSensitiveClassifier ccc = new CostSensitiveClassifier();
		ccc.setClassifier(nb);
		ccc.setCostMatrix(cm);
		ccc.setMinimizeExpectedCost(false);
		ccc.setSeed(1);
		return ccc;
	}
	private Classifier getJ48(){
		J48 nb = new J48();
		nb.setConfidenceFactor(0.14f);
		nb.setBinarySplits(true);
		nb.setMinNumObj(6);
		nb.setNumFolds(2);
		nb.setReducedErrorPruning(false);
		nb.setSaveInstanceData(false);
		nb.setSeed(1);
		nb.setSubtreeRaising(true);
		nb.setUnpruned(false);
		nb.setUseLaplace(false);
		return nb;
	}
	private Classifier getNaiveBayes(){
		NaiveBayes nb = new NaiveBayes();
		nb.setDisplayModelInOldFormat(true);
		nb.setUseKernelEstimator(false);
		nb.setUseSupervisedDiscretization(true);
		return nb;
	}
	private Classifier getNaiveBayesCostMatrix(){
		NaiveBayes nb = new NaiveBayes();
		nb.setDisplayModelInOldFormat(true);
		nb.setUseKernelEstimator(false);
		nb.setUseSupervisedDiscretization(true);

		CostMatrix cm = new CostMatrix(3);
		cm.setElement(0, 0, 0.0);
		cm.setElement(1, 0, 3.32);
		cm.setElement(2, 0, 8.44);

		cm.setElement(0, 1, 1.0);
		cm.setElement(1, 1, 0.0);
		cm.setElement(2, 1, 8.44);

		cm.setElement(0, 2, 1.0);
		cm.setElement(1, 2, 3.32);
		cm.setElement(2, 2, 0.0);
		
		CostSensitiveClassifier ccc = new CostSensitiveClassifier();
		ccc.setClassifier(nb);
		ccc.setCostMatrix(cm);
		ccc.setMinimizeExpectedCost(false);
		ccc.setSeed(1);
		return ccc;
	}
	private String getSummary(Evaluation eval , Classifier cfr, long total, boolean print){
		try {
		String summary = "=== Classifier model (full training set) ===\n\n" + cfr.toString() +"\nTime taken to build model: "+((double)total/1000)+" seconds\n\n=== Stratified cross-validation ===\n=== Summary ===\n"+eval.toSummaryString()+"\n"+eval.toClassDetailsString()+"\n"+eval.toMatrixString();
		if(print)
			System.out.println(summary);
		return summary;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}
	private <T> void checkKeys1(Map<String,Map<String,T>> map1, Map<Integer,String> map2){
		for(String s : map1.keySet()){
			for(String t : map1.get(s).keySet()){
				if(!map2.containsValue(s+","+t))
					System.out.println( s + "\t" + t);
			}
		}
		
	}
	private void createClassMapData() {
		String[] indexedString = new String[3135];
		for(String stateKey : demographicsMap.keySet()){
			Set<String> countyKeys = demographicsMap.get(stateKey).keySet();
			for(String countykey : countyKeys){
				Demographics demographics = demographicsMap.get(stateKey).get(countykey);
				LeadingCausesOfDeath leadingCausesOfDeath = deathMap.get(stateKey).get(countykey);
				MeasuresOfBirthAndDeath measuresOfBirthAndDeath = measuresMap.get(stateKey).get(countykey);
				PreventiveServicesUse preventiveServicesUse = preventiveMap.get(stateKey).get(countykey);
				RelativeHealthImportance relativeHealthImportance = relativeMap.get(stateKey).get(countykey);
				RiskFactorsAndAccessToCare riskFactorsAndAccessToCare = riskMap.get(stateKey).get(countykey);
				SummaryMeasuresOfHealth summaryMeasuresOfHealth = summaryMap.get(stateKey).get(countykey);
				VunerablePopsAndEnvHealth vunerablePopsAndEnvHealth = vunerableMap.get(stateKey).get(countykey);
				Weather weather = weatherMap.get(stateKey).get(countykey);
				Integer index = mapIndex.get(stateKey).get(countykey);
				if(index != null){
					double percentLungCancerDeaths = measuresOfBirthAndDeath.getLung_Cancer()/demographics.getPopulation_Size();
					double percentBreastCancerDeaths = measuresOfBirthAndDeath.getBrst_Cancer()/demographics.getPopulation_Size();
					double percentColonCancerDeaths = measuresOfBirthAndDeath.getCol_Cancer()/demographics.getPopulation_Size();

					int classifier = CancerModel.lowMedHighClassifier(percentBreastCancerDeaths, percentColonCancerDeaths, percentLungCancerDeaths);
					indexedString[index-1] = (classifier == 1 ? "1" : "0") + "\t" + (classifier == 2 ? "1" : "0") + "\t" + (classifier == 3 ? "1" : "0") + "\t" + (classifier == -1 ? "1" : "0");
				}
			}
		}
		for(String s : indexedString){
			System.out.println(s);
		}
	}
	private <T, S> void checkKeys(Map<String,Map<String,T>> map1, Map<String,Map<String,S>> map2){
		for(String s : map1.keySet()){
			for(String t : map1.get(s).keySet()){

				if(map2.get(s) == null)
					System.out.println(s);
				S object = map2.get(s).get(t);
				if(object == null)
					System.out.println( s + "\t" + t);
			}
		}
		
	}
	private void processDataCostMatrix3() {
		BufferedReader reader;
		try 
		{
			reader = new BufferedReader(new FileReader(TEST_FILE_LOCATION));
			Instances data = new Instances(reader);
			reader.close();
			// setting class attribute
			data.setClassIndex(data.numAttributes() - 1);
			data.deleteAttributeAt(0);
			data.deleteAttributeAt(0);
			
			List<J48Thread> threads = new ArrayList<J48Thread>();
//			Correct59.56961199869579 getConfidenceFactor 0.33 getBinarySplits true getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
			threads.add(new J48Thread(data, 5, true));
			threads.get(0).setConfidenceFactor(0.33f, 0.33f, 0.01f);
			threads.get(0).setNumFolds(3, 3, 1);
			threads.get(0).setMinNumObjects(9, 9, 1);
			threads.get(0).setSeed(1, 1, 1);
			threads.get(0).setReducedErrorPruning("true");
			threads.get(0).setSaveInstanceData("false");
			threads.get(0).setSubtreeRaising("false");
			threads.get(0).setUseLaplace("true");
			threads.get(0).setBinarySplit("true");
			threads.get(0).start();
			
			while(true){
				boolean sleep = false;
				for(J48Thread j48 : threads){
					if(!j48.isFinished()){
						sleep = true;
						break;
					}
				}
				if(sleep)
					Thread.sleep(1000);
				else
					break;
			}

			List<J48> models = new ArrayList<J48>();
			List<Evaluation> evals = new ArrayList<Evaluation>();
			
			for(J48Thread j48 : threads){
				models.addAll(j48.getBestModels());
				evals.addAll(j48.getBestModelsEval());
				System.out.println("took " + j48.getRunTime() + " long");
			}
			
			for(int counter = 0 ; counter < models.size(); counter++){
				System.out.println("Correct" + evals.get(counter).pctCorrect() + " getConfidenceFactor " + models.get(counter).getConfidenceFactor() + " getBinarySplits " + models.get(counter).getBinarySplits() + " getMinNumObj " + models.get(counter).getMinNumObj() + " getNumFolds " + models.get(counter).getNumFolds() + " getReducedErrorPruning " + models.get(counter).getReducedErrorPruning() + " getSaveInstanceData " + models.get(counter).getSaveInstanceData() + " getSeed " + models.get(counter).getSeed() + " getSubtreeRaising " + models.get(counter).getSubtreeRaising() + " getUnpruned " + models.get(counter).getUnpruned() + " getUseLaplace " + models.get(counter).getUseLaplace());
			}
		
			J48 s = threads.get(0).getBestModels().get(0);
			
			s.buildClassifier(data);
			
//			for(int k = 1; k < 500; k++){
//				Instance i = data.instance(k);
//				
//				System.out.println(s.classifyInstance(i));
//			}

			StringBuilder pw = new StringBuilder();
			pw.append("@relation cancer-weather").append("\n");
			pw.append("@attribute getEcol_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getSalm_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getShig_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getCarbon_Monoxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getLead_Ind {Y,N}").append("\n");
			pw.append("@attribute getNitrogen_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getOzone_Ind {Y,N}").append("\n");
			pw.append("@attribute getParticulate_Matter_Ind {Y,N}").append("\n");
			pw.append("@attribute getSulfur_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getToxic_Chem numeric").append("\n");
			pw.append("@attribute precipitationInches numeric").append("\n");
			pw.append("@attribute cancerLevelClass {1,2,3}").append("\n");
			pw.append("\n");
			pw.append("@data").append("\n");
			pw.append("N,N,Y,N,N,N,N,N,N,81501,50.46,?");
			
			Instances i = new Instances(new BufferedReader(new StringReader(pw.toString())));
			i.setClassIndex(i.numAttributes() - 1);
			System.out.println(s.classifyInstance(i.instance(0)));
			
			for(J48Thread thread : threads)
				thread.interrupt();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void processDataCostMatrix2() {
		BufferedReader reader;
		try 
		{
			reader = new BufferedReader(new FileReader(TEST_FILE_LOCATION));
			Instances data = new Instances(reader);
			reader.close();
			// setting class attribute
			data.setClassIndex(data.numAttributes() - 1);
			data.deleteAttributeAt(0);
			data.deleteAttributeAt(0);
			
			List<J48Thread> threads = new ArrayList<J48Thread>();
			
			threads.add(new J48Thread(data, 5, true));
			threads.get(0).setConfidenceFactor(0.18f, 0.23f, 0.01f);
			threads.get(0).setNumFolds(2, 12, 1);
			threads.get(0).setMinNumObjects(1, 16, 1);
			threads.get(0).setSeed(1, 2, 1);
			threads.get(0).setReducedErrorPruning("both");
			threads.get(0).setSaveInstanceData("both");
			threads.get(0).setSubtreeRaising("both");
			threads.get(0).setUseLaplace("both");
			threads.get(0).setBinarySplit("both");
			threads.get(0).start();

			threads.add(new J48Thread(data, 5, true));
			threads.get(1).setConfidenceFactor(0.23f, 0.28f, 0.01f);
			threads.get(1).setNumFolds(2, 12, 1);
			threads.get(1).setMinNumObjects(1, 16, 1);
			threads.get(1).setSeed(1, 2, 1);
			threads.get(1).setReducedErrorPruning("both");
			threads.get(1).setSaveInstanceData("both");
			threads.get(1).setSubtreeRaising("both");
			threads.get(1).setUseLaplace("both");
			threads.get(1).setBinarySplit("both");
			threads.get(1).start();

			threads.add(new J48Thread(data, 5, true));
			threads.get(2).setConfidenceFactor(0.28f, 0.33f, 0.01f);
			threads.get(2).setNumFolds(2, 12, 1);
			threads.get(2).setMinNumObjects(1, 16, 1);
			threads.get(2).setSeed(1, 2, 1);
			threads.get(2).setReducedErrorPruning("both");
			threads.get(2).setSaveInstanceData("both");
			threads.get(2).setSubtreeRaising("both");
			threads.get(2).setUseLaplace("both");
			threads.get(2).setBinarySplit("both");
			threads.get(2).start();

			threads.add(new J48Thread(data, 5, true));
			threads.get(3).setConfidenceFactor(0.33f, 0.36f, 0.01f);
			threads.get(3).setNumFolds(2, 12, 1);
			threads.get(3).setMinNumObjects(1, 16, 1);
			threads.get(3).setSeed(1, 2, 1);
			threads.get(3).setReducedErrorPruning("both");
			threads.get(3).setSaveInstanceData("both");
			threads.get(3).setSubtreeRaising("both");
			threads.get(3).setUseLaplace("both");
			threads.get(3).setBinarySplit("both");
			threads.get(3).start();
			
			while(true){
				boolean sleep = false;
				for(J48Thread j48 : threads){
					if(!j48.isFinished()){
						sleep = true;
						break;
					}
				}
				if(sleep)
					Thread.sleep(1000);
				else
					break;
			}

			List<J48> models = new ArrayList<J48>();
			List<Evaluation> evals = new ArrayList<Evaluation>();
			
			for(J48Thread j48 : threads){
				models.addAll(j48.getBestModels());
				evals.addAll(j48.getBestModelsEval());
				System.out.println("took " + j48.getRunTime() + " long");
			}
			
			for(int counter = 0 ; counter < models.size(); counter++){
				System.out.println("Correct" + evals.get(counter).pctCorrect() + " getConfidenceFactor " + models.get(counter).getConfidenceFactor() + " getBinarySplits " + models.get(counter).getBinarySplits() + " getMinNumObj " + models.get(counter).getMinNumObj() + " getNumFolds " + models.get(counter).getNumFolds() + " getReducedErrorPruning " + models.get(counter).getReducedErrorPruning() + " getSaveInstanceData " + models.get(counter).getSaveInstanceData() + " getSeed " + models.get(counter).getSeed() + " getSubtreeRaising " + models.get(counter).getSubtreeRaising() + " getUnpruned " + models.get(counter).getUnpruned() + " getUseLaplace " + models.get(counter).getUseLaplace());
			}
			
//			took 0001-01-01 08:52:23.232 long
//			took 0001-01-01 08:05:11.655 long
//			took 0001-01-01 08:55:45.994 long
//			took 0001-01-01 07:07:15.167 long
//			Correct59.56961199869579 getConfidenceFactor 0.18 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.18 getBinarySplits true getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.18 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.18 getBinarySplits true getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.18 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData true getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.23 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.23 getBinarySplits true getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.23 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.23 getBinarySplits true getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.23 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData true getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.28 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.28 getBinarySplits true getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.28 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.28 getBinarySplits true getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.28 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData true getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.33 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.33 getBinarySplits true getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.33 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.33 getBinarySplits true getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.56961199869579 getConfidenceFactor 0.33 getBinarySplits false getMinNumObj 9 getNumFolds 3 getReducedErrorPruning true getSaveInstanceData true getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace true
			
			J48 s = threads.get(0).getBestModels().get(0);
			
			s.buildClassifier(data);
			
//			for(int k = 1; k < 500; k++){
//				Instance i = data.instance(k);
//				
//				System.out.println(s.classifyInstance(i));
//			}

			StringBuilder pw = new StringBuilder();
			pw.append("@relation cancer-weather").append("\n");
			pw.append("@attribute getEcol_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getSalm_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getShig_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getCarbon_Monoxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getLead_Ind {Y,N}").append("\n");
			pw.append("@attribute getNitrogen_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getOzone_Ind {Y,N}").append("\n");
			pw.append("@attribute getParticulate_Matter_Ind {Y,N}").append("\n");
			pw.append("@attribute getSulfur_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getToxic_Chem numeric").append("\n");
			pw.append("@attribute precipitationInches numeric").append("\n");
			pw.append("@attribute cancerLevelClass {1,2,3}").append("\n");
			pw.append("\n");
			pw.append("@data").append("\n");
			pw.append("N,N,Y,N,N,N,N,N,N,81501,50.46,?");
			
			Instances i = new Instances(new BufferedReader(new StringReader(pw.toString())));
			i.setClassIndex(i.numAttributes() - 1);
			System.out.println(s.classifyInstance(i.instance(0)));

			for(J48Thread thread : threads)
				thread.interrupt();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void processDataCostMatrix() {
		BufferedReader reader;
		try 
		{
			reader = new BufferedReader(new FileReader(TEST_FILE_LOCATION));
			Instances data = new Instances(reader);
			reader.close();
			// setting class attribute
			data.setClassIndex(data.numAttributes() - 1);
			data.deleteAttributeAt(0);
			data.deleteAttributeAt(0);
			
			List<J48Thread> threads = new ArrayList<J48Thread>();

			threads.add(new J48Thread(data, 5, true));
			threads.get(0).setConfidenceFactor(0.01f, 0.10f, 0.02f);
			threads.get(0).setNumFolds(2, 12, 2);
			threads.get(0).setMinNumObjects(1, 16, 5);
			threads.get(0).setSeed(1, 2, 1);
			threads.get(0).setReducedErrorPruning("both");
			threads.get(0).setSaveInstanceData("both");
			threads.get(0).setSubtreeRaising("both");
			threads.get(0).setUseLaplace("both");
			threads.get(0).setBinarySplit("both");
			threads.get(0).start();

			threads.add(new J48Thread(data, 5, true));
			threads.get(1).setConfidenceFactor(0.10f, 0.20f, 0.02f);
			threads.get(1).setNumFolds(2, 12, 2);
			threads.get(1).setMinNumObjects(1, 16, 5);
			threads.get(1).setSeed(1, 2, 1);
			threads.get(1).setReducedErrorPruning("both");
			threads.get(1).setSaveInstanceData("both");
			threads.get(1).setSubtreeRaising("both");
			threads.get(1).setUseLaplace("both");
			threads.get(1).setBinarySplit("both");
			threads.get(1).start();

			threads.add(new J48Thread(data, 5, true));
			threads.get(2).setConfidenceFactor(0.20f, 0.30f, 0.02f);
			threads.get(2).setNumFolds(2, 12, 2);
			threads.get(2).setMinNumObjects(1, 16, 5);
			threads.get(2).setSeed(1, 2, 1);
			threads.get(2).setReducedErrorPruning("both");
			threads.get(2).setSaveInstanceData("both");
			threads.get(2).setSubtreeRaising("both");
			threads.get(2).setUseLaplace("both");
			threads.get(2).setBinarySplit("both");
			threads.get(2).start();

			threads.add(new J48Thread(data, 5, true));
			threads.get(3).setConfidenceFactor(0.30f, 0.45f, 0.02f);
			threads.get(3).setNumFolds(2, 12, 2);
			threads.get(3).setMinNumObjects(1, 16, 5);
			threads.get(3).setSeed(1, 2, 1);
			threads.get(3).setReducedErrorPruning("both");
			threads.get(3).setSaveInstanceData("both");
			threads.get(3).setSubtreeRaising("both");
			threads.get(3).setUseLaplace("both");
			threads.get(3).setBinarySplit("both");
			threads.get(3).start();
			
			while(true){
				boolean sleep = false;
				for(J48Thread j48 : threads){
					if(!j48.isFinished()){
						sleep = true;
						break;
					}
				}
				if(sleep)
					Thread.sleep(1000);
				else
					break;
			}

			List<J48> models = new ArrayList<J48>();
			List<Evaluation> evals = new ArrayList<Evaluation>();
			
			for(J48Thread j48 : threads){
				models.addAll(j48.getBestModels());
				evals.addAll(j48.getBestModelsEval());
				System.out.println("took " + j48.getRunTime() + " long");
			}
			
			for(int counter = 0 ; counter < models.size(); counter++){
				System.out.println("Correct" + evals.get(counter).pctCorrect() + " getConfidenceFactor " + models.get(counter).getConfidenceFactor() + " getBinarySplits " + models.get(counter).getBinarySplits() + " getMinNumObj " + models.get(counter).getMinNumObj() + " getNumFolds " + models.get(counter).getNumFolds() + " getReducedErrorPruning " + models.get(counter).getReducedErrorPruning() + " getSaveInstanceData " + models.get(counter).getSaveInstanceData() + " getSeed " + models.get(counter).getSeed() + " getSubtreeRaising " + models.get(counter).getSubtreeRaising() + " getUnpruned " + models.get(counter).getUnpruned() + " getUseLaplace " + models.get(counter).getUseLaplace());
			}
			
//			took 0001-01-01 01:12:37.136 long
//			took 0001-01-01 01:07:46.856 long
//			took 0001-01-01 01:04:31.794 long
//			took 0001-01-01 01:38:46.206 long
//			Correct58.95011411803065 getConfidenceFactor 0.109999985 getBinarySplits false getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct58.95011411803065 getConfidenceFactor 0.109999985 getBinarySplits true getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct58.95011411803065 getConfidenceFactor 0.109999985 getBinarySplits false getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct58.95011411803065 getConfidenceFactor 0.109999985 getBinarySplits true getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct58.95011411803065 getConfidenceFactor 0.109999985 getBinarySplits false getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 2 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.308770785784155 getConfidenceFactor 0.17999999 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.308770785784155 getConfidenceFactor 0.17999999 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.308770785784155 getConfidenceFactor 0.17999999 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.308770785784155 getConfidenceFactor 0.17999999 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.308770785784155 getConfidenceFactor 0.17999999 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 2 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct59.2761656341702 getConfidenceFactor 0.2 getBinarySplits false getMinNumObj 11 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct59.2761656341702 getConfidenceFactor 0.2 getBinarySplits true getMinNumObj 11 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct59.2761656341702 getConfidenceFactor 0.2 getBinarySplits false getMinNumObj 11 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct59.2761656341702 getConfidenceFactor 0.2 getBinarySplits true getMinNumObj 11 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct59.2761656341702 getConfidenceFactor 0.2 getBinarySplits false getMinNumObj 11 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct59.08053472448647 getConfidenceFactor 0.36000004 getBinarySplits false getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct59.08053472448647 getConfidenceFactor 0.36000004 getBinarySplits true getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct59.08053472448647 getConfidenceFactor 0.36000004 getBinarySplits false getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct59.08053472448647 getConfidenceFactor 0.36000004 getBinarySplits true getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct59.08053472448647 getConfidenceFactor 0.36000004 getBinarySplits false getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 2 getSubtreeRaising true getUnpruned false getUseLaplace false
			
			
			J48 s = threads.get(0).getBestModels().get(0);
			
			s.buildClassifier(data);
			
//			for(int k = 1; k < 500; k++){
//				Instance i = data.instance(k);
//				
//				System.out.println(s.classifyInstance(i));
//			}

			StringBuilder pw = new StringBuilder();
			pw.append("@relation cancer-weather").append("\n");
			pw.append("@attribute getEcol_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getSalm_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getShig_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getCarbon_Monoxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getLead_Ind {Y,N}").append("\n");
			pw.append("@attribute getNitrogen_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getOzone_Ind {Y,N}").append("\n");
			pw.append("@attribute getParticulate_Matter_Ind {Y,N}").append("\n");
			pw.append("@attribute getSulfur_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getToxic_Chem numeric").append("\n");
			pw.append("@attribute precipitationInches numeric").append("\n");
			pw.append("@attribute cancerLevelClass {1,2,3}").append("\n");
			pw.append("\n");
			pw.append("@data").append("\n");
			pw.append("N,N,Y,N,N,N,N,N,N,81501,50.46,?");
			
			Instances i = new Instances(new BufferedReader(new StringReader(pw.toString())));
			i.setClassIndex(i.numAttributes() - 1);
			System.out.println(s.classifyInstance(i.instance(0)));
			
			for(J48Thread thread : threads)
				thread.interrupt();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void processData4() {
		BufferedReader reader;
		try 
		{
			reader = new BufferedReader(new FileReader(TEST_FILE_LOCATION));
			Instances data = new Instances(reader);
			reader.close();
			// setting class attribute
			data.setClassIndex(data.numAttributes() - 1);
			data.deleteAttributeAt(0);
			data.deleteAttributeAt(0);
			
			List<J48Thread> threads = new ArrayList<J48Thread>();
//Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
			threads.add(new J48Thread(data, 5, false));
			threads.get(0).setConfidenceFactor(0.14f, 0.14f, 0.01f);
			threads.get(0).setNumFolds(2, 2, 1);
			threads.get(0).setMinNumObjects(6, 6, 1);
			threads.get(0).setSeed(1, 1, 1);
			threads.get(0).setReducedErrorPruning("false");
			threads.get(0).setSaveInstanceData("false");
			threads.get(0).setSubtreeRaising("true");
			threads.get(0).setUseLaplace("false");
			threads.get(0).setBinarySplit("true");
			threads.get(0).start();
			
			while(true){
				boolean sleep = false;
				for(J48Thread j48 : threads){
					if(!j48.isFinished()){
						sleep = true;
						break;
					}
				}
				if(sleep)
					Thread.sleep(1000);
				else
					break;
			}

			List<J48> models = new ArrayList<J48>();
			List<Evaluation> evals = new ArrayList<Evaluation>();
			
			for(J48Thread j48 : threads){
				models.addAll(j48.getBestModels());
				evals.addAll(j48.getBestModelsEval());
				System.out.println("took " + j48.getRunTime() + " long");
			}
			
			for(int counter = 0 ; counter < models.size(); counter++){
				System.out.println("Correct" + evals.get(counter).pctCorrect() + " getConfidenceFactor " + models.get(counter).getConfidenceFactor() + " getBinarySplits " + models.get(counter).getBinarySplits() + " getMinNumObj " + models.get(counter).getMinNumObj() + " getNumFolds " + models.get(counter).getNumFolds() + " getReducedErrorPruning " + models.get(counter).getReducedErrorPruning() + " getSaveInstanceData " + models.get(counter).getSaveInstanceData() + " getSeed " + models.get(counter).getSeed() + " getSubtreeRaising " + models.get(counter).getSubtreeRaising() + " getUnpruned " + models.get(counter).getUnpruned() + " getUseLaplace " + models.get(counter).getUseLaplace());
			}
			
			J48 s = threads.get(0).getBestModels().get(0);
			
			s.buildClassifier(data);
			
//			for(int k = 1; k < 500; k++){
//				Instance i = data.instance(k);
//				
//				System.out.println(s.classifyInstance(i));
//			}

			StringBuilder pw = new StringBuilder();
			pw.append("@relation cancer-weather").append("\n");
			pw.append("@attribute getEcol_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getSalm_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getShig_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getCarbon_Monoxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getLead_Ind {Y,N}").append("\n");
			pw.append("@attribute getNitrogen_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getOzone_Ind {Y,N}").append("\n");
			pw.append("@attribute getParticulate_Matter_Ind {Y,N}").append("\n");
			pw.append("@attribute getSulfur_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getToxic_Chem numeric").append("\n");
			pw.append("@attribute precipitationInches numeric").append("\n");
			pw.append("@attribute cancerLevelClass {1,2,3}").append("\n");
			pw.append("\n");
			pw.append("@data").append("\n");
			pw.append("N,N,Y,N,N,N,N,N,N,81501,50.46,?");
			
			Instances i = new Instances(new BufferedReader(new StringReader(pw.toString())));
			i.setClassIndex(i.numAttributes() - 1);
			System.out.println(s.classifyInstance(i.instance(0)));
			
			for(J48Thread thread : threads)
				thread.interrupt();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void processData3() {
		BufferedReader reader;
		try 
		{
			reader = new BufferedReader(new FileReader(TEST_FILE_LOCATION));
			Instances data = new Instances(reader);
			reader.close();
			// setting class attribute
			data.setClassIndex(data.numAttributes() - 1);
			data.deleteAttributeAt(0);
			data.deleteAttributeAt(0);
			
			List<J48Thread> threads = new ArrayList<J48Thread>();
			
			threads.add(new J48Thread(data, 5, false));
			threads.get(0).setConfidenceFactor(0.13f, 0.13f, 0.01f);
			threads.get(0).setNumFolds(2, 5, 1);
			threads.get(0).setMinNumObjects(2, 10, 1);
			threads.get(0).setSeed(1, 7, 2);
			threads.get(0).setReducedErrorPruning("both");
			threads.get(0).setSaveInstanceData("both");
			threads.get(0).setSubtreeRaising("both");
			threads.get(0).setUseLaplace("both");
			threads.get(0).setBinarySplit("both");
			threads.get(0).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(1).setConfidenceFactor(0.14f, 0.14f, 0.01f);
			threads.get(1).setNumFolds(2, 5, 1);
			threads.get(1).setMinNumObjects(2, 10, 1);
			threads.get(1).setSeed(1, 7, 2);
			threads.get(1).setReducedErrorPruning("both");
			threads.get(1).setSaveInstanceData("both");
			threads.get(1).setSubtreeRaising("both");
			threads.get(1).setUseLaplace("both");
			threads.get(1).setBinarySplit("both");
			threads.get(1).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(2).setConfidenceFactor(0.15f, 0.15f, 0.01f);
			threads.get(2).setNumFolds(2, 5, 1);
			threads.get(2).setMinNumObjects(2, 10, 1);
			threads.get(2).setSeed(1, 7, 2);
			threads.get(2).setReducedErrorPruning("both");
			threads.get(2).setSaveInstanceData("both");
			threads.get(2).setSubtreeRaising("both");
			threads.get(2).setUseLaplace("both");
			threads.get(2).setBinarySplit("both");
			threads.get(2).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(3).setConfidenceFactor(0.14f, 0.14f, 0.01f);
			threads.get(3).setNumFolds(2, 5, 1);
			threads.get(3).setMinNumObjects(2, 10, 1);
			threads.get(3).setSeed(7, 12, 2);
			threads.get(3).setReducedErrorPruning("both");
			threads.get(3).setSaveInstanceData("both");
			threads.get(3).setSubtreeRaising("both");
			threads.get(3).setUseLaplace("both");
			threads.get(3).setBinarySplit("both");
			threads.get(3).start();
			
			while(true){
				boolean sleep = false;
				for(J48Thread j48 : threads){
					if(!j48.isFinished()){
						sleep = true;
						break;
					}
				}
				if(sleep)
					Thread.sleep(1000);
				else
					break;
			}

			List<J48> models = new ArrayList<J48>();
			List<Evaluation> evals = new ArrayList<Evaluation>();
			
			for(J48Thread j48 : threads){
				models.addAll(j48.getBestModels());
				evals.addAll(j48.getBestModelsEval());
				System.out.println("took " + j48.getRunTime() + " long");
			}
			
			for(int counter = 0 ; counter < models.size(); counter++){
				System.out.println("Correct" + evals.get(counter).pctCorrect() + " getConfidenceFactor " + models.get(counter).getConfidenceFactor() + " getBinarySplits " + models.get(counter).getBinarySplits() + " getMinNumObj " + models.get(counter).getMinNumObj() + " getNumFolds " + models.get(counter).getNumFolds() + " getReducedErrorPruning " + models.get(counter).getReducedErrorPruning() + " getSaveInstanceData " + models.get(counter).getSaveInstanceData() + " getSeed " + models.get(counter).getSeed() + " getSubtreeRaising " + models.get(counter).getSubtreeRaising() + " getUnpruned " + models.get(counter).getUnpruned() + " getUseLaplace " + models.get(counter).getUseLaplace());
			}
			
//			took 0001-01-01 00:24:03.066 long
//			took 0001-01-01 00:24:45.509 long
//			took 0001-01-01 00:27:51.46 long
//			took 0001-01-01 00:20:36.787 long
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 3 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 3 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 3 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 7 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 7 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 7 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 7 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 9 getSubtreeRaising true getUnpruned false getUseLaplace false
			
			
			J48 s = threads.get(0).getBestModels().get(0);
			
			s.buildClassifier(data);
			
//			for(int k = 1; k < 500; k++){
//				Instance i = data.instance(k);
//				
//				System.out.println(s.classifyInstance(i));
//			}

			StringBuilder pw = new StringBuilder();
			pw.append("@relation cancer-weather").append("\n");
			pw.append("@attribute getEcol_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getSalm_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getShig_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getCarbon_Monoxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getLead_Ind {Y,N}").append("\n");
			pw.append("@attribute getNitrogen_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getOzone_Ind {Y,N}").append("\n");
			pw.append("@attribute getParticulate_Matter_Ind {Y,N}").append("\n");
			pw.append("@attribute getSulfur_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getToxic_Chem numeric").append("\n");
			pw.append("@attribute precipitationInches numeric").append("\n");
			pw.append("@attribute cancerLevelClass {1,2,3}").append("\n");
			pw.append("\n");
			pw.append("@data").append("\n");
			pw.append("N,N,Y,N,N,N,N,N,N,81501,50.46,?");
			
			Instances i = new Instances(new BufferedReader(new StringReader(pw.toString())));
			i.setClassIndex(i.numAttributes() - 1);
			System.out.println(s.classifyInstance(i.instance(0)));
			
			for(J48Thread thread : threads)
				thread.interrupt();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void processData2() {
		BufferedReader reader;
		try 
		{
			reader = new BufferedReader(new FileReader(TEST_FILE_LOCATION));
			Instances data = new Instances(reader);
			reader.close();
			// setting class attribute
			data.setClassIndex(data.numAttributes() - 1);
			data.deleteAttributeAt(0);
			data.deleteAttributeAt(0);
			
			List<J48Thread> threads = new ArrayList<J48Thread>();

			threads.add(new J48Thread(data, 5, false));
			threads.get(0).setConfidenceFactor(0.10f, 0.13f, 0.01f);
			threads.get(0).setNumFolds(2, 30, 5);
			threads.get(0).setMinNumObjects(1, 30, 5);
			threads.get(0).setSeed(1, 30, 5);
			threads.get(0).setReducedErrorPruning("both");
			threads.get(0).setSaveInstanceData("both");
			threads.get(0).setSubtreeRaising("both");
			threads.get(0).setUseLaplace("both");
			threads.get(0).setBinarySplit("both");
			threads.get(0).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(1).setConfidenceFactor(0.12f, 0.16f, 0.01f);
			threads.get(1).setNumFolds(2, 30, 5);
			threads.get(1).setMinNumObjects(1, 30, 5);
			threads.get(1).setSeed(1, 30, 5);
			threads.get(1).setReducedErrorPruning("both");
			threads.get(1).setSaveInstanceData("both");
			threads.get(1).setSubtreeRaising("both");
			threads.get(1).setUseLaplace("both");
			threads.get(1).setBinarySplit("both");
			threads.get(1).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(2).setConfidenceFactor(0.15f, 0.18f, 0.01f);
			threads.get(2).setNumFolds(2, 30, 5);
			threads.get(2).setMinNumObjects(1, 30, 5);
			threads.get(2).setSeed(1, 30, 5);
			threads.get(2).setReducedErrorPruning("both");
			threads.get(2).setSaveInstanceData("both");
			threads.get(2).setSubtreeRaising("both");
			threads.get(2).setUseLaplace("both");
			threads.get(2).setBinarySplit("both");
			threads.get(2).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(3).setConfidenceFactor(0.17f, 0.20f, 0.01f);
			threads.get(3).setNumFolds(2, 30, 5);
			threads.get(3).setMinNumObjects(1, 30, 5);
			threads.get(3).setSeed(1, 30, 5);
			threads.get(3).setReducedErrorPruning("both");
			threads.get(3).setSaveInstanceData("both");
			threads.get(3).setSubtreeRaising("both");
			threads.get(3).setUseLaplace("both");
			threads.get(3).setBinarySplit("both");
			threads.get(3).start();
			
			while(true){
				boolean sleep = false;
				for(J48Thread j48 : threads){
					if(!j48.isFinished()){
						sleep = true;
						break;
					}
				}
				if(sleep)
					Thread.sleep(1000);
				else
					break;
			}

			List<J48> models = new ArrayList<J48>();
			List<Evaluation> evals = new ArrayList<Evaluation>();
			
			for(J48Thread j48 : threads){
				models.addAll(j48.getBestModels());
				evals.addAll(j48.getBestModelsEval());
				System.out.println("took " + j48.getRunTime() + " long");
			}
			
			for(int counter = 0 ; counter < models.size(); counter++){
				System.out.println("Correct" + evals.get(counter).pctCorrect() + " getConfidenceFactor " + models.get(counter).getConfidenceFactor() + " getBinarySplits " + models.get(counter).getBinarySplits() + " getMinNumObj " + models.get(counter).getMinNumObj() + " getNumFolds " + models.get(counter).getNumFolds() + " getReducedErrorPruning " + models.get(counter).getReducedErrorPruning() + " getSaveInstanceData " + models.get(counter).getSaveInstanceData() + " getSeed " + models.get(counter).getSeed() + " getSubtreeRaising " + models.get(counter).getSubtreeRaising() + " getUnpruned " + models.get(counter).getUnpruned() + " getUseLaplace " + models.get(counter).getUseLaplace());
			}
			
//			took 0001-01-01 03:13:10.936 long
//			took 0001-01-01 04:15:53.543 long
//			took 0001-01-01 03:32:18.243 long
//			took 0001-01-01 03:54:44.427 long
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.13 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 6 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.56830779263123 getConfidenceFactor 0.14 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 6 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 6 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.47049233778937 getConfidenceFactor 0.17 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct71.47049233778937 getConfidenceFactor 0.17 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct71.47049233778937 getConfidenceFactor 0.17 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct71.47049233778937 getConfidenceFactor 0.17 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct71.47049233778937 getConfidenceFactor 0.17 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 6 getSubtreeRaising true getUnpruned false getUseLaplace true

			
			
			J48 s = threads.get(0).getBestModels().get(0);
			
			s.buildClassifier(data);
			
//			for(int k = 1; k < 500; k++){
//				Instance i = data.instance(k);
//				
//				System.out.println(s.classifyInstance(i));
//			}

			StringBuilder pw = new StringBuilder();
			pw.append("@relation cancer-weather").append("\n");
			pw.append("@attribute getEcol_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getSalm_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getShig_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getCarbon_Monoxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getLead_Ind {Y,N}").append("\n");
			pw.append("@attribute getNitrogen_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getOzone_Ind {Y,N}").append("\n");
			pw.append("@attribute getParticulate_Matter_Ind {Y,N}").append("\n");
			pw.append("@attribute getSulfur_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getToxic_Chem numeric").append("\n");
			pw.append("@attribute precipitationInches numeric").append("\n");
			pw.append("@attribute cancerLevelClass {1,2,3}").append("\n");
			pw.append("\n");
			pw.append("@data").append("\n");
			pw.append("N,N,Y,N,N,N,N,N,N,81501,50.46,?");
			
			Instances i = new Instances(new BufferedReader(new StringReader(pw.toString())));
			i.setClassIndex(i.numAttributes() - 1);
			System.out.println(s.classifyInstance(i.instance(0)));
			
			for(J48Thread thread : threads)
				thread.interrupt();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void processData() {
		BufferedReader reader;
		try 
		{
			reader = new BufferedReader(new FileReader(TEST_FILE_LOCATION));
			Instances data = new Instances(reader);
			reader.close();
			// setting class attribute
			data.setClassIndex(data.numAttributes() - 1);
			data.deleteAttributeAt(0);
			data.deleteAttributeAt(0);
			
			List<J48Thread> threads = new ArrayList<J48Thread>();

			threads.add(new J48Thread(data, 5, false));
			threads.get(0).setConfidenceFactor(0.01f, 0.10f, 0.05f);
			threads.get(0).setNumFolds(2, 30, 5);
			threads.get(0).setMinNumObjects(1, 30, 5);
			threads.get(0).setSeed(1, 30, 5);
			threads.get(0).setReducedErrorPruning("both");
			threads.get(0).setSaveInstanceData("both");
			threads.get(0).setSubtreeRaising("both");
			threads.get(0).setUseLaplace("both");
			threads.get(0).setBinarySplit("both");
			threads.get(0).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(1).setConfidenceFactor(0.10f, 0.20f, 0.05f);
			threads.get(1).setNumFolds(2, 30, 5);
			threads.get(1).setMinNumObjects(1, 30, 5);
			threads.get(1).setSeed(1, 30, 5);
			threads.get(1).setReducedErrorPruning("both");
			threads.get(1).setSaveInstanceData("both");
			threads.get(1).setSubtreeRaising("both");
			threads.get(1).setUseLaplace("both");
			threads.get(1).setBinarySplit("both");
			threads.get(1).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(2).setConfidenceFactor(0.20f, 0.30f, 0.05f);
			threads.get(2).setNumFolds(2, 30, 5);
			threads.get(2).setMinNumObjects(1, 30, 5);
			threads.get(2).setSeed(1, 30, 5);
			threads.get(2).setReducedErrorPruning("both");
			threads.get(2).setSaveInstanceData("both");
			threads.get(2).setSubtreeRaising("both");
			threads.get(2).setUseLaplace("both");
			threads.get(2).setBinarySplit("both");
			threads.get(2).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(3).setConfidenceFactor(0.30f, 0.40f, 0.05f);
			threads.get(3).setNumFolds(2, 30, 5);
			threads.get(3).setMinNumObjects(1, 30, 5);
			threads.get(3).setSeed(1, 30, 5);
			threads.get(3).setReducedErrorPruning("both");
			threads.get(3).setSaveInstanceData("both");
			threads.get(3).setSubtreeRaising("both");
			threads.get(3).setUseLaplace("both");
			threads.get(3).setBinarySplit("both");
			threads.get(3).start();

			threads.add(new J48Thread(data, 5, false));
			threads.get(3).setConfidenceFactor(0.40f, 0.45f, 0.05f);
			threads.get(3).setNumFolds(2, 30, 5);
			threads.get(3).setMinNumObjects(1, 30, 5);
			threads.get(3).setSeed(1, 30, 5);
			threads.get(3).setReducedErrorPruning("both");
			threads.get(3).setSaveInstanceData("both");
			threads.get(3).setSubtreeRaising("both");
			threads.get(3).setUseLaplace("both");
			threads.get(3).setBinarySplit("both");
			threads.get(3).start();
			
			while(true){
				boolean sleep = false;
				for(J48Thread j48 : threads){
					if(!j48.isFinished()){
						sleep = true;
						break;
					}
				}
				if(sleep)
					Thread.sleep(1000);
				else
					break;
			}

			List<J48> models = new ArrayList<J48>();
			List<Evaluation> evals = new ArrayList<Evaluation>();
			
			for(J48Thread j48 : threads){
				models.addAll(j48.getBestModels());
				evals.addAll(j48.getBestModelsEval());
				System.out.println("took " + j48.getRunTime() + " long");
			}
			
			for(int counter = 0 ; counter < models.size(); counter++){
				System.out.println("Correct" + evals.get(counter).pctCorrect() + " getConfidenceFactor " + models.get(counter).getConfidenceFactor() + " getBinarySplits " + models.get(counter).getBinarySplits() + " getMinNumObj " + models.get(counter).getMinNumObj() + " getNumFolds " + models.get(counter).getNumFolds() + " getReducedErrorPruning " + models.get(counter).getReducedErrorPruning() + " getSaveInstanceData " + models.get(counter).getSaveInstanceData() + " getSeed " + models.get(counter).getSeed() + " getSubtreeRaising " + models.get(counter).getSubtreeRaising() + " getUnpruned " + models.get(counter).getUnpruned() + " getUseLaplace " + models.get(counter).getUseLaplace());
			}
			
//			took 0001-01-01 03:19:16.952 long
//			took 0001-01-01 02:42:18.191 long
//			took 0001-01-01 02:50:50.53 long
//			took 0001-01-01 02:42:12.107 long
//			took 0001-01-01 02:36:39.417 long
//			Correct71.11183567003586 getConfidenceFactor 0.11 getBinarySplits false getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.11183567003586 getConfidenceFactor 0.11 getBinarySplits true getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.11183567003586 getConfidenceFactor 0.11 getBinarySplits false getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.11183567003586 getConfidenceFactor 0.11 getBinarySplits true getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.11183567003586 getConfidenceFactor 0.11 getBinarySplits false getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 6 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits true getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.50309748940333 getConfidenceFactor 0.15 getBinarySplits false getMinNumObj 6 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 6 getSubtreeRaising true getUnpruned false getUseLaplace false
//			Correct71.47049233778937 getConfidenceFactor 0.2 getBinarySplits false getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct71.47049233778937 getConfidenceFactor 0.2 getBinarySplits true getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct71.47049233778937 getConfidenceFactor 0.2 getBinarySplits false getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct71.47049233778937 getConfidenceFactor 0.2 getBinarySplits true getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct71.47049233778937 getConfidenceFactor 0.2 getBinarySplits false getMinNumObj 1 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 6 getSubtreeRaising true getUnpruned false getUseLaplace true
//			Correct71.34007173133355 getConfidenceFactor 0.3 getBinarySplits false getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct71.34007173133355 getConfidenceFactor 0.3 getBinarySplits true getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct71.34007173133355 getConfidenceFactor 0.3 getBinarySplits false getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct71.34007173133355 getConfidenceFactor 0.3 getBinarySplits true getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct71.34007173133355 getConfidenceFactor 0.3 getBinarySplits false getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 6 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct71.34007173133355 getConfidenceFactor 0.4 getBinarySplits false getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct71.34007173133355 getConfidenceFactor 0.4 getBinarySplits true getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct71.34007173133355 getConfidenceFactor 0.4 getBinarySplits false getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct71.34007173133355 getConfidenceFactor 0.4 getBinarySplits true getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData true getSeed 1 getSubtreeRaising false getUnpruned false getUseLaplace false
//			Correct71.34007173133355 getConfidenceFactor 0.4 getBinarySplits false getMinNumObj 16 getNumFolds 2 getReducedErrorPruning false getSaveInstanceData false getSeed 6 getSubtreeRaising false getUnpruned false getUseLaplace false

			
			
			J48 s = threads.get(0).getBestModels().get(0);
			
			s.buildClassifier(data);
			
//			for(int k = 1; k < 500; k++){
//				Instance i = data.instance(k);
//				
//				System.out.println(s.classifyInstance(i));
//			}

			StringBuilder pw = new StringBuilder();
			pw.append("@relation cancer-weather").append("\n");
			pw.append("@attribute getEcol_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getSalm_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getShig_Rpt_Ind {Y,N}").append("\n");
			pw.append("@attribute getCarbon_Monoxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getLead_Ind {Y,N}").append("\n");
			pw.append("@attribute getNitrogen_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getOzone_Ind {Y,N}").append("\n");
			pw.append("@attribute getParticulate_Matter_Ind {Y,N}").append("\n");
			pw.append("@attribute getSulfur_Dioxide_Ind {Y,N}").append("\n");
			pw.append("@attribute getToxic_Chem numeric").append("\n");
			pw.append("@attribute precipitationInches numeric").append("\n");
			pw.append("@attribute cancerLevelClass {1,2,3}").append("\n");
			pw.append("\n");
			pw.append("@data").append("\n");
			pw.append("N,N,Y,N,N,N,N,N,N,81501,50.46,?");
			
			Instances i = new Instances(new BufferedReader(new StringReader(pw.toString())));
			i.setClassIndex(i.numAttributes() - 1);
			System.out.println(s.classifyInstance(i.instance(0)));
			
			for(J48Thread thread : threads)
				thread.interrupt();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void writeFile() {
		PrintWriter pw;
		try {
			pw = new PrintWriter(new FileWriter(new File(TEST_FILE_LOCATION)));
			pw.println("@relation cancer-weather");
			pw.println();
			pw.println("@attribute state string");
			pw.println("@attribute county string");
//			pw.println("@attribute percentBreastCancerDeaths numeric");
//			pw.println("@attribute percentLungCancerDeaths numeric");
//			pw.println("@attribute percentColonCancerDeaths numeric");
			pw.println("@attribute getEcol_Rpt_Ind {Y,N}");
			pw.println("@attribute getSalm_Rpt_Ind {Y,N}");
			pw.println("@attribute getShig_Rpt_Ind {Y,N}");
			pw.println("@attribute getCarbon_Monoxide_Ind {Y,N}");
			pw.println("@attribute getLead_Ind {Y,N}");
			pw.println("@attribute getNitrogen_Dioxide_Ind {Y,N}");
			pw.println("@attribute getOzone_Ind {Y,N}");
			pw.println("@attribute getParticulate_Matter_Ind {Y,N}");
			pw.println("@attribute getSulfur_Dioxide_Ind {Y,N}");
			pw.println("@attribute getToxic_Chem numeric");
			pw.println("@attribute precipitationInches numeric");
			pw.println("@attribute cancerLevelClass {1,2,3}");
			pw.println();
			pw.println("@data");
			
//			for(String stateKey : processingStates){
			for(String stateKey : demographicsMap.keySet()){
				Set<String> countyKeys = demographicsMap.get(stateKey).keySet();
				for(String countykey : countyKeys){
					Demographics demographics = demographicsMap.get(stateKey).get(countykey);
					LeadingCausesOfDeath leadingCausesOfDeath = deathMap.get(stateKey).get(countykey);
					MeasuresOfBirthAndDeath measuresOfBirthAndDeath = measuresMap.get(stateKey).get(countykey);
					PreventiveServicesUse preventiveServicesUse = preventiveMap.get(stateKey).get(countykey);
					RelativeHealthImportance relativeHealthImportance = relativeMap.get(stateKey).get(countykey);
					RiskFactorsAndAccessToCare riskFactorsAndAccessToCare = riskMap.get(stateKey).get(countykey);
					SummaryMeasuresOfHealth summaryMeasuresOfHealth = summaryMap.get(stateKey).get(countykey);
					VunerablePopsAndEnvHealth vunerablePopsAndEnvHealth = vunerableMap.get(stateKey).get(countykey);
					Weather weather = weatherMap.get(stateKey).get(countykey);
					
					DecimalFormat dfpercent = new DecimalFormat("#.####");
					
					double percentLungCancerDeaths = measuresOfBirthAndDeath.getLung_Cancer()/demographics.getPopulation_Size();
					double percentBreastCancerDeaths = measuresOfBirthAndDeath.getBrst_Cancer()/demographics.getPopulation_Size();
					double percentColonCancerDeaths = measuresOfBirthAndDeath.getCol_Cancer()/demographics.getPopulation_Size();
//					percentBreastCancerDeaths = Double.NEGATIVE_INFINITY;
//					percentColonCancerDeaths = Double.NEGATIVE_INFINITY;
					int classifier = CancerModel.lowMedHighClassifier(percentBreastCancerDeaths, percentColonCancerDeaths, percentLungCancerDeaths);
					pw.println(
							    "'" + demographics.getCHSI_State_Abbr().replace("'", "\\'")  + "'"  
							 + ",'" + demographics.getCHSI_County_Name().replace("'", "\\'") + "'" 
//							 +  "," + ((percentBreastCancerDeaths == Double.NEGATIVE_INFINITY) ? "?" : dfpercent.format(percentBreastCancerDeaths)) 
//							 +  "," + ((percentLungCancerDeaths == Double.NEGATIVE_INFINITY) ? "?" : dfpercent.format(percentLungCancerDeaths)) 
//							 +  "," + ((percentColonCancerDeaths == Double.NEGATIVE_INFINITY) ? "?" : dfpercent.format(percentColonCancerDeaths))
							 +  "," + (vunerablePopsAndEnvHealth.getEcol_Rpt_Ind() == 4 ? "N" : vunerablePopsAndEnvHealth.getEcol_Rpt_Ind() == 3 ? "Y" : "?")
							 +  "," + (vunerablePopsAndEnvHealth.getSalm_Rpt_Ind() == 4 ? "N" : vunerablePopsAndEnvHealth.getSalm_Rpt_Ind() == 3 ? "Y" : "?")
							 +  "," + (vunerablePopsAndEnvHealth.getShig_Rpt_Ind() == 4 ? "N" : vunerablePopsAndEnvHealth.getShig_Rpt_Ind() == 3 ? "Y" : "?")
							 +  "," + (vunerablePopsAndEnvHealth.getCarbon_Monoxide_Ind() == 1 ? "N" : vunerablePopsAndEnvHealth.getCarbon_Monoxide_Ind() == 2 ? "Y" : "?")
							 +  "," + (vunerablePopsAndEnvHealth.getLead_Ind() == 1 ? "N" : vunerablePopsAndEnvHealth.getLead_Ind() == 2 ? "Y" : "?")
							 +  "," + (vunerablePopsAndEnvHealth.getNitrogen_Dioxide_Ind() == 1 ? "N" : vunerablePopsAndEnvHealth.getNitrogen_Dioxide_Ind() == 2 ? "Y" : "?")
							 +  "," + (vunerablePopsAndEnvHealth.getOzone_Ind() == 1 ? "N" : vunerablePopsAndEnvHealth.getOzone_Ind() == 2 ? "Y" : "?")
							 +  "," + (vunerablePopsAndEnvHealth.getParticulate_Matter_Ind() == 1 ? "N" : vunerablePopsAndEnvHealth.getParticulate_Matter_Ind() == 2 ? "Y" : "?")
							 +  "," + (vunerablePopsAndEnvHealth.getSulfur_Dioxide_Ind() == 1 ? "N" : vunerablePopsAndEnvHealth.getSulfur_Dioxide_Ind() == 2 ? "Y" : "?")
							 +  "," + (vunerablePopsAndEnvHealth.getToxic_Chem() < 0 ? "?" : vunerablePopsAndEnvHealth.getToxic_Chem())
							 +  "," + (weather == null ? "?" : weather.getInches())
							 +  "," + (classifier == -1 ? "?" : classifier)
							   );
				}
			}
			pw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	private void readFiles() {
		BufferedReader br;
		try {
			br = new BufferedReader(new FileReader(new File("./dataFiles/DEMOGRAPHICS.csv")));
			demographicsMap = DemographicsMapper.process(br);
			br.close();
//			DemographicsMapper.info(demographicsMap);
			
			br = new BufferedReader(new FileReader(new File("./dataFiles/LEADINGCAUSESOFDEATH.csv")));
			deathMap = LeadingCausesOfDeathMapper.process(br);
			br.close();

			br = new BufferedReader(new FileReader(new File("./dataFiles/MEASURESOFBIRTHANDDEATH.csv")));
			measuresMap = MeasuresOfBirthAndDeathMapper.process(br);
			br.close();
//			MeasuresOfBirthAndDeathMapper.info(measuresMap);

			br = new BufferedReader(new FileReader(new File("./dataFiles/PREVENTIVESERVICESUSE.csv")));
			preventiveMap = PreventiveServicesUseMapper.process(br);
			br.close();

			br = new BufferedReader(new FileReader(new File("./dataFiles/RELATIVEHEALTHIMPORTANCE.csv")));
			relativeMap = RelativeHealthImportanceMapper.process(br);
			br.close();

			br = new BufferedReader(new FileReader(new File("./dataFiles/RISKFACTORSANDACCESSTOCARE.csv")));
			riskMap = RiskFactorsAndAccessToCareMapper.process(br);
			br.close();

			br = new BufferedReader(new FileReader(new File("./dataFiles/SUMMARYMEASURESOFHEALTH.csv")));
			summaryMap = SummaryMeasuresOfHealthMapper.process(br);
			br.close();
			
			br = new BufferedReader(new FileReader(new File("./dataFiles/VUNERABLEPOPSANDENVHEALTH.csv")));
			vunerableMap = VunerablePopsAndEnvHealthMapper.process(br);
			br.close();
//			VunerablePopsAndEnvHealthMapper.info(vunerableMap);

			br = new BufferedReader(new FileReader(new File("./dataFiles/WeatherData")));
			weatherMap = WeatherFileMapper.process(br);
			br.close();
			
			br = new BufferedReader(new FileReader(new File("./dataFiles/MapIndexData.txt")));
			mapIndex = MapIndexMapper.process(br);
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {new DataProcessing();}
}
